#include "parser.h"

#include "pp/ppchar.h"
#include "pp/ppcomment.h"
#include "pp/ppif.h"
#include "pp/ppinclude.h"
#include "pp/ppkeyword.h"
#include "pp/ppnumber.h"
#include "pp/ppoperator.h"
#include "pp/ppstring.h"
#include "pp/ppsymbol.h"
#include "pp/ppsynopt.h"

#include "object/cenum.h"
#include "object/cmacro.h"
#include "object/cstruct.h"
#include "object/cunion.h"
#include "object/func.h"
#include "object/type.h"
#include "object/var.h"

namespace losor
{
	int goct[256];
	int gdec[256];
	int ghex[256];
	int gopt[256];
	int gword[256];
	map<string,int> gkeyword;
	
	void init_constmap();
	
	int pp_parser( code &_code, list<ppobject*> &ppobj )
	{
		const char *ptr = _code.str;
		ppobject *obj = NULL;

		init_constmap();
		
		switch( *ptr )
		{
		case '\'':      // character
			break;
		case '"':       // string
			break;
		case '/':       // comment or operator
			break;
		case '#':       // preprocessor
			break;
		default:        // number or operator or symbol or keyword or synopt
		}
	}
	
	int parser( const list<ppobject*> &_code, list<object*> &obj )
	{
	}

	void init_constmap()
	{
		int i;
		static const char* word[] = {
			"auto","break","case","char","const","continue","default",
			"do","double","else","enum","extern","float","for","goto",
			"if","inline","int","long","register","restrict","return",
			"short","signed","sizeof","static","struct","switch","typedef",
			"union","unsigned","void","volatile","while","_BOOL","_COMPLEX",
			"_IMAGINARY",
		};
		for( i = 0; i < sizeof(word) / sizeof(word[0]); ++i )
			gkeyword[word[i]] = 1;
		    
		memset( goct,   0, sizeof( goct ) );
		memset( gdec, 0, sizeof( gdec ) );
		memset( ghex, 0, sizeof( ghex ) );
		memset( gopt, 0, sizeof( gopt ) );
		memset( gword, 0, sizeof( gword ) );
			
		for( i = '0'; i <= '7'; ++i )
			goct[i] = 1;
		for( i = '0'; i <='9'; ++i )
		{
			gdec[i] = 1;
			ghex[i] = 1;
		}
		for( i = 'a'; i <= 'f'; ++i )
		{
			ghex[i] = 1;
			ghex[i+'A'-'a'] = 1;
		}
		for( i = 'a'; i <= 'z'; ++i )
		{
			gword[i] = 1;
			gword[i+'A'-'a'] = 1;
		}
		gopt['~'] = gopt['!'] = gopt['%'] =
			gopt['^'] = gopt['&'] = gopt['*'] =
			gopt['('] = gopt[')'] = gopt['-'] =
			gopt['+'] = gopt['='] = gopt['['] =
			gopt[']'] = gopt['|'] = gopt[':'] =
			gopt[','] = gopt['<'] = gopt['>'] =
			gopt['.'] = gopt['?'] = gopt['/'];
	}
}

